package net.sourceforge.openclixml.ext;

import net.sourceforge.openclixml.ClixmlException;
import net.sourceforge.openclixml.EvaluationFailedException;
import net.sourceforge.openclixml.environment.IEnvironment;

import org.w3c.dom.Document;

import java.util.Map;


/**
 *
 * @version $Revision: 49 $
 * @author dominikjungo
 *
 * Last changed: $Date: 2008-04-09 22:06:24 +0200 (Wed, 09 Apr 2008) $
 * The License for this file can be found in doc/Licenses/license-OpenCliXML.txt
 */
public class RuleType extends net.sourceforge.openclixml.autogen.RuleType {
    /**
    * Evaluates the child.
    *
    * {@inheritDoc}
    *
    */
    @Override
    public boolean evalDelegated(
        final IEnvironment<String, String> environment,
        final Map<String, Document> systemUnderTest)
        throws EvaluationFailedException {
        FormulaType child = null;

        try {
            child = getChildElement(); //ElementManipulator.getChild(this);
        } catch (ClixmlException e) {
            throw new EvaluationFailedException("child could be fetched");
        }

        Boolean result = null;

        result = child.eval(environment, systemUnderTest);

        if (result == null) {
            throw new EvaluationFailedException("evaluation returned to null");
        }

        setSuccess(result);

        return result;
    }
}
